﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using fastJSON;
using todo.Model;

namespace todo
{
    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    [ComVisible(true)]
    public class OptionsHost
    {
        public event EventHandler OnClose;
        private Options _options;

        public OptionsHost()
        {
            _options = new Options();
            _options.EmailTo = App.Settings.EmailTo;
            _options.TopDownMode = App.Settings.TopDownMode;
            _options.OpenLastFileOnStart = App.Settings.OpenLastFileOnStart;
        }

        private void FireClose()
        {
            var handler = OnClose;
            if (handler != null) handler(this, EventArgs.Empty);
        }

        public void close(bool save)
        {
            if (save)
            {
                App.Settings.EmailTo = _options.EmailTo;
                App.Settings.TopDownMode = _options.TopDownMode;
                App.Settings.OpenLastFileOnStart = _options.OpenLastFileOnStart;
            }
            FireClose();
        }

        public Options getOptions()
        {
            return _options;
        }

        public string GetLocalizedStrings()
        {
#if zh
            var map = new Dictionary<string, string> {
                    {"title.options", "选项"},
                    {"title.todoDirection", "添加方向"},
                    {"title.reminderSettings", "提醒设置"},
                    {"title.misc", "其它"},
                    {"lbl.bottomUp", "从底往上"},
                    {"lbl.topDown", "从上到下"},
                    {"lbl.emailTo", "邮件地址"},
                    {"lbl.openLastFileOnStart", "启动时打开最近打开的待办列表"},
                    {"action.ok", "确定"},
                    {"action.cancel", "取消"},
            };
            return JSON.Instance.ToJSON(map);
#else
            return null;
#endif
        }
    }
}